package com.example.demo2.config;

import com.example.demo2.util.RabbitMqUtils;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class TTLDirectRabbitMqConfigation {
    //创建交换机 路由模式
    @Bean
    public DirectExchange ttldirectExchange(){
        return new DirectExchange(RabbitMqUtils.TTLORDER_EXCHANGE,true,false);
    }
    //创建队列,队列过期时间设置
    @Bean
    public Queue ttlweixin_direct(){
        Map<String,Object> arg=new HashMap<>();
        arg.put("x-message-ttl",5000);
        //绑定死信队列和路由key
        arg.put("x-dead-letter-exchange",RabbitMqUtils.DEAD_EXCHANGE);
        arg.put("x-dead-letter-routing-key","dead");
        return new Queue("ttlweixin_direct",true,false,false,arg);
    }
    //创建队列,队列过期时间设置
    @Bean
    public Queue ttlweixin_direct1(){
        return new Queue("ttlweixin_direct_common",true);
    }

    //队列绑定交换机
    @Bean
    public Binding bindingttl(){
        return BindingBuilder.bind(ttlweixin_direct()).to(ttldirectExchange()).with("ttl");
    }
    //队列绑定交换机
    @Bean
    public Binding bindingttl1(){
        return BindingBuilder.bind(ttlweixin_direct1()).to(ttldirectExchange()).with("ttl_common");
    }

}
